//
//  YZMRedPacketActCell.m
//  YZMicroStock
//
//  Created by apple on 17/5/2.
//  Copyright © 2017年 cqjr. All rights reserved.
//

#import "YZMRedPacketActCell.h"
#import <ColorUtils/ColorUtils.h>

@interface YZMRedPacketActCell ()
@property (nonatomic, strong) UILabel *titleLB;
@property (nonatomic, strong) UIImageView *hotImageView;
@property (nonatomic, strong) UILabel *detailLB;
@property (nonatomic, strong) UIButton *redPackBtn;

@end

@implementation YZMRedPacketActCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self createObjects];
        self.leftMargin = 0.0;
        self.rightMargin = 0.0;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    return self;
}

- (void)createObjects {
    
    WS(ws)
    self.titleLB = [YZMAppStyle labelWithMediumWhite];
    [self addSubview:self.titleLB];
    [self.titleLB mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.equalTo(ws).offset(20);
    }];
    
    self.hotImageView = [[UIImageView alloc] init];
    [self addSubview:self.hotImageView];
    [self.hotImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(ws.titleLB.mas_centerY).offset(-5);
        make.left.equalTo(ws.titleLB.mas_right).offset(2);
        make.width.height.mas_equalTo(10);
        
    }];
    
    self.detailLB = [YZMAppStyle labelWithSmallLightGray];
    [self addSubview:self.detailLB];
    [self.detailLB mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(ws.titleLB.mas_bottom).with.offset(7);
        make.left.equalTo(ws.titleLB);
    }];
    
    self.redPackBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.redPackBtn.enabled = YES;
    [self addSubview:self.redPackBtn];
//    [self.redPackBtn setTitle:@"50元" forState:UIControlStateNormal];
    [self.redPackBtn setTitleColor:[YZMAppStyle colorForWhite] forState:UIControlStateDisabled];
    [self.redPackBtn setTitleColor:[UIColor colorWithString:@"#FFE15D"] forState:UIControlStateNormal];
    [self.redPackBtn setBackgroundImage:[UIImage imageNamed:@"icon_packet_go"] forState:UIControlStateNormal];
    [self.redPackBtn setBackgroundImage:[UIImage imageNamed:@"icon_packet_done"] forState:UIControlStateDisabled];
    [self.redPackBtn addTarget:self action:@selector(actionMethod) forControlEvents:UIControlEventTouchUpInside];
    self.redPackBtn.titleLabel.font = [YZMAppStyle mediumSizeFont];
    self.redPackBtn.titleEdgeInsets = UIEdgeInsetsMake(0, -63, 0, 0);
    [self.redPackBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(ws);
        make.right.equalTo(ws).offset(-20);
    }];
    [self addSubview:self.redPackBtn];
    [self.redPackBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(ws);
        make.right.equalTo(ws).offset(-20);
    }];
}


-(void)setModel:(YZMRedPacketModel *)model{
    
    self.titleLB.text = model.name;
    self.detailLB.text = model.redPacketdescription;
    [self.redPackBtn setTitle:[NSString stringWithFormat:@"%@元",@(model.value)] forState:UIControlStateNormal];
    if (model.status == 0) {

        self.redPackBtn.enabled = YES;
        [self.redPackBtn setBackgroundImage:[UIImage imageNamed:@"icon_packet_go"] forState:UIControlStateNormal];
        self.userInteractionEnabled = YES;
//        self.titleLB.textColor = [YZMAppStyle colorForRiseText];
    } else if (model.status == 1) {

        self.redPackBtn.enabled = YES;
        [self.redPackBtn setBackgroundImage:[UIImage imageNamed:@"icon_packet_grey"] forState:UIControlStateNormal];
        self.userInteractionEnabled = YES;
//        self.titleLB.textColor = [YZMAppStyle colorForRiseText];
    } else if (model.status == 2) {

        self.redPackBtn.enabled = NO;
        [self.redPackBtn setBackgroundImage:[UIImage imageNamed:@"icon_packet_done"] forState:UIControlStateNormal];
        self.userInteractionEnabled = NO;
//        self.titleLB.textColor = [YZMAppStyle colorForLightGrayText];
    }
}

-(void)setIsLastestCell:(BOOL)isLastestCell{
    
    if (isLastestCell) {
        
        [self.hotImageView setImage:[UIImage imageNamed:@"icon_new"]];
    }else{
        
        [self.hotImageView setImage:[UIImage imageNamed:@"icon_hot"]];
    }
}

- (void)actionMethod {
    
    if (self.action) {
        
        self.action();
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
